﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class unpingjiainfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["type"] == null)
                {
                    return ;
                }
                if (Request.Params["recid"] == null)
                {
                    return ;
                }
                bind1();
            }
        }
        private void bind1()
        {
            CurrentUserLabel.Text = AliApi.appUserId;

            lypingjia p1 = lypingjia.Find(" recid = " + Request.Params["recid"].ToString());
            Label2.Text = p1.RECID.ToString();
            Label3.Text = p1.cbuseridby.ToString();
            Label4.Text = p1.cbuserid.ToString();
            if (p1.jcpoint.Value == 1)
            {
                Label5.Text = "好评";
            }
            else
            {
                Label5.Text = "差评";
            }
            Label6.Text = p1.cbtitle.ToString();
            Literal1.Text = p1.jcdesc2.ToString();
            if (Request.Params["type"].ToString() == "2")
            {
                Label1.Visible = false;
            }
            else
            {
                Label1.Visible = true ;
            }
        }

        protected void 取消操作_Click(object sender, EventArgs e)
        {
            if (!cbuser.ValidatePassword(CurrentUserLabel.Text, PasswordTextBox.Text))
            {
                MessageBox.Show(this.Page,"对不起，密码不正确!");
                return;
            }

            lypingjia p1 = lypingjia.Find(" recid = " + Request.Params["recid"].ToString());
            if (p1.cbstatus.ToString() == "取消")
            {
                MessageBox.Show(this.Page, "该记录已取消。");
                return;
            }
            if (AliApi.appUserId == p1.cbuserid.ToString() && Request.Params["type"].ToString() == "2")
            {
                cbuser u = cbuser.Find(" cbuserid = '" + AliApi.appUserId + "'");
                if (u.cbmoney.Value >= 50)
                {
                    cbmoneytrans mt = cbmoneytrans.Find("1=2");
                    mt.cbmoneytrantype.Value = "取消评价";
                    mt.cbuserid.Value = AliApi.appUserId;
                    mt.jccreatedate.Value = DateTime.Now;
                    mt.jccreatetime.StringValue = DateTime.Now.ToLongTimeString();
                    mt.cbmoney.Value = -50;
                    mt.RefTable.Value = "lypingjia";
                    mt.RefRecID.Value = p1.RECID.ToString();
                    mt.Insert();
                    u.cbmoney.Value += -50;
                    u.cbmoneyF.Value += 50;
                    u.Modify();
                    p1.cbstatus.Value = "取消";
                    p1.Modify();
                    MessageBox.Show(this.Page, "操作成功");
                    return;
                }
                else
                {
                    MessageBox.Show(this.Page, "余额不足50元");
                    return;
                }
            }
            MessageBox.Show(this.Page, "操作失败");
            
            

            
        }
    }
}
